package party.loveit.download.core;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import party.loveit.download.listener.IDListener;


/**
 * 下载实体类
 * Download entity.
 *
 * @author Jerry 2015-05-16
 */
public class DLInfo implements Serializable, Comparable<DLInfo> {
    public long totalBytes;
    public long currentBytes;
    public String fileName;
    public String dirPath;
    public String baseUrl;
    public String realUrl;
    public int dlState;
    public String imgUrl;
    public String videoName;
    public String videoTime;
    public String speed;

    int redirect;
    boolean hasListener;
    boolean isResume;
    boolean isStop;
    String mimeType;
    String eTag;
    String disposition;
    String location;
    List<DLHeader> requestHeaders;
    final List<DLThreadInfo> threads;
    IDListener listener;
    File file;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof DLInfo)) return false;

        DLInfo dlInfo = (DLInfo) o;

        return baseUrl.equals(dlInfo.baseUrl);

    }

    @Override
    public int hashCode() {
        return baseUrl.hashCode();
    }

   public DLInfo() {
        threads = new ArrayList<>();
    }

    synchronized void addDLThread(DLThreadInfo info) {
        threads.add(info);
    }

    synchronized void removeDLThread(DLThreadInfo info) {
        threads.remove(info);
    }

    @Override
    public int compareTo(DLInfo dlInfo) {

        return this.dlState - dlInfo.dlState;
    }
}